﻿namespace mVids
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class videoUC : UserControl
    {
        private ComboBox artistBox;
        private IContainer components = null;
        private mVids.database db;
        private Button deleteButton;
        private TextBox filenameBox;
        private Label label1;
        private Label label2;
        private Label label3;
        private Label label4;
        private Label label5;
        private Label label6;
        private Label label8;
        private TextBox lengthBox;
        private string oldfilename;
        private TextBox playcountBox;
        private ComboBox ratingBox;
        private Button saveButton;
        private TextBox scoreBox;
        private TextBox songBox;

        public videoUC(object datab, string artist, List<string> artists, string song, string filename, string rating, string playcount, string score, string length)
        {
            this.InitializeComponent();
            this.db = (mVids.database) datab;
            this.oldfilename = filename;
            this.filenameBox.Text = filename;
            this.artistBox.Items.AddRange(artists.ToArray());
            this.artistBox.SelectedText = artist;
            this.songBox.Text = song;
            this.ratingBox.SelectedText = rating;
            this.playcountBox.Text = playcount;
            this.scoreBox.Text = score;
            this.lengthBox.Text = length;
        }

        private void deleteButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete this video?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if (this.db.delEntry(this.oldfilename))
                {
                    MessageBox.Show("Video Deleted from DB");
                }
                else
                {
                    MessageBox.Show("Error Deleting Video from DB");
                }
                base.Dispose();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.ratingBox = new ComboBox();
            this.label8 = new Label();
            this.filenameBox = new TextBox();
            this.label6 = new Label();
            this.lengthBox = new TextBox();
            this.label5 = new Label();
            this.scoreBox = new TextBox();
            this.label4 = new Label();
            this.label3 = new Label();
            this.playcountBox = new TextBox();
            this.label1 = new Label();
            this.label2 = new Label();
            this.songBox = new TextBox();
            this.artistBox = new ComboBox();
            this.saveButton = new Button();
            this.deleteButton = new Button();
            base.SuspendLayout();
            this.ratingBox.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.ratingBox.FormattingEnabled = true;
            this.ratingBox.Items.AddRange(new object[] { "1", "2", "3", "4", "5" });
            this.ratingBox.Location = new Point(0xca, 0xa4);
            this.ratingBox.Name = "ratingBox";
            this.ratingBox.Size = new Size(0x3d, 0x15);
            this.ratingBox.TabIndex = 0x24;
            this.ratingBox.SelectedIndexChanged += new EventHandler(this.ratingBox_SelectedIndexChanged);
            this.label8.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.label8.AutoSize = true;
            this.label8.Location = new Point(0x25, 0x81);
            this.label8.Name = "label8";
            this.label8.Size = new Size(0x34, 13);
            this.label8.TabIndex = 0x2c;
            this.label8.Text = "Filename:";
            this.filenameBox.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.filenameBox.Location = new Point(0x5e, 0x7e);
            this.filenameBox.Name = "filenameBox";
            this.filenameBox.Size = new Size(0x19c, 20);
            this.filenameBox.TabIndex = 0x22;
            this.label6.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.label6.AutoSize = true;
            this.label6.Location = new Point(0x125, 0xca);
            this.label6.Name = "label6";
            this.label6.Size = new Size(0x2b, 13);
            this.label6.TabIndex = 0x2b;
            this.label6.Text = "Length:";
            this.lengthBox.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.lengthBox.Location = new Point(0x150, 0xc7);
            this.lengthBox.Name = "lengthBox";
            this.lengthBox.Size = new Size(0x3d, 20);
            this.lengthBox.TabIndex = 0x27;
            this.label5.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.label5.AutoSize = true;
            this.label5.Location = new Point(0x9f, 0xca);
            this.label5.Name = "label5";
            this.label5.Size = new Size(0x26, 13);
            this.label5.TabIndex = 0x2a;
            this.label5.Text = "Score:";
            this.scoreBox.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.scoreBox.Location = new Point(0xcb, 0xc7);
            this.scoreBox.Name = "scoreBox";
            this.scoreBox.ReadOnly = true;
            this.scoreBox.Size = new Size(0x3d, 20);
            this.scoreBox.TabIndex = 0x29;
            this.label4.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.label4.AutoSize = true;
            this.label4.Location = new Point(0x113, 0xa7);
            this.label4.Name = "label4";
            this.label4.Size = new Size(0x3d, 13);
            this.label4.TabIndex = 40;
            this.label4.Text = "Play Count:";
            this.label3.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.label3.AutoSize = true;
            this.label3.Location = new Point(0x9e, 0xa7);
            this.label3.Name = "label3";
            this.label3.Size = new Size(0x29, 13);
            this.label3.TabIndex = 0x26;
            this.label3.Text = "Rating:";
            this.playcountBox.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.playcountBox.Location = new Point(0x150, 0xa4);
            this.playcountBox.Name = "playcountBox";
            this.playcountBox.Size = new Size(0x3d, 20);
            this.playcountBox.TabIndex = 0x25;
            this.playcountBox.TextChanged += new EventHandler(this.playcountBox_TextChanged);
            this.label1.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.label1.AutoSize = true;
            this.label1.Enabled = false;
            this.label1.Location = new Point(0x39, 0x2c);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x21, 13);
            this.label1.TabIndex = 0x20;
            this.label1.Text = "Artist:";
            this.label2.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.label2.AutoSize = true;
            this.label2.Location = new Point(0x37, 0x58);
            this.label2.Name = "label2";
            this.label2.Size = new Size(0x23, 13);
            this.label2.TabIndex = 0x23;
            this.label2.Text = "Song:";
            this.songBox.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.songBox.Location = new Point(0x5e, 0x55);
            this.songBox.Name = "songBox";
            this.songBox.Size = new Size(0x19c, 20);
            this.songBox.TabIndex = 0x21;
            this.artistBox.FormattingEnabled = true;
            this.artistBox.Location = new Point(0x5e, 0x29);
            this.artistBox.Name = "artistBox";
            this.artistBox.Size = new Size(0x19c, 0x15);
            this.artistBox.TabIndex = 0x2d;
            this.saveButton.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.saveButton.BackColor = SystemColors.ButtonFace;
            this.saveButton.FlatAppearance.BorderColor = Color.Red;
            this.saveButton.Location = new Point(0x253, 0x27);
            this.saveButton.Name = "saveButton";
            this.saveButton.Size = new Size(90, 0x43);
            this.saveButton.TabIndex = 0x30;
            this.saveButton.Text = "Save Record";
            this.saveButton.UseVisualStyleBackColor = true;
            this.saveButton.Click += new EventHandler(this.saveButton_Click);
            this.deleteButton.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.deleteButton.Location = new Point(0x253, 0x76);
            this.deleteButton.Name = "deleteButton";
            this.deleteButton.Size = new Size(90, 0x23);
            this.deleteButton.TabIndex = 0x31;
            this.deleteButton.Text = "Delete Record";
            this.deleteButton.UseVisualStyleBackColor = true;
            this.deleteButton.Click += new EventHandler(this.deleteButton_Click);
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.deleteButton);
            base.Controls.Add(this.saveButton);
            base.Controls.Add(this.artistBox);
            base.Controls.Add(this.ratingBox);
            base.Controls.Add(this.label8);
            base.Controls.Add(this.filenameBox);
            base.Controls.Add(this.label6);
            base.Controls.Add(this.lengthBox);
            base.Controls.Add(this.label5);
            base.Controls.Add(this.scoreBox);
            base.Controls.Add(this.label4);
            base.Controls.Add(this.label3);
            base.Controls.Add(this.playcountBox);
            base.Controls.Add(this.label1);
            base.Controls.Add(this.label2);
            base.Controls.Add(this.songBox);
            base.Name = "videoUC";
            base.Size = new Size(700, 350);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void playcountBox_TextChanged(object sender, EventArgs e)
        {
            try
            {
                this.scoreBox.Text = Convert.ToString((int) (int.Parse(this.ratingBox.Text) * int.Parse(this.playcountBox.Text)));
            }
            catch
            {
            }
        }

        private void ratingBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                this.scoreBox.Text = Convert.ToString((int) (int.Parse(this.ratingBox.Text) * int.Parse(this.playcountBox.Text)));
            }
            catch
            {
            }
        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            if (this.db.updateEntireRecord(this.oldfilename, this.filenameBox.Text, this.db.resolveArtistName(this.artistBox.SelectedItem.ToString()), this.songBox.Text, this.playcountBox.Text, this.ratingBox.Text, this.lengthBox.Text, this.scoreBox.Text))
            {
                MessageBox.Show(this.artistBox.SelectedText + " - " + this.songBox.Text + " updated", "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
            }
        }
    }
}

